<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
  
  require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'asset'.DS.'rendfield.php');

  JHTML::_('behavior.tooltip');
?>

<script type="text/javascript" language="javascript">
<!--
//function check_field_type(field_value)
//{
//	var form = document.adminForm;
//	if (field_value=='IMAGE')
//	{
//		form.image_width.disabled = false;
//		form.image_height.disabled = false;
//	}
//	else
//	{
//		form.image_width.disabled = true;
//		form.image_height.disabled = true;
//		form.image_width.value = '';
//		form.image_height.value = '';
//	}
//}
function submitbutton(pressbutton) {
	var form = document.adminForm;

	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if ( pressbutton == 'save' || pressbutton == 'apply' ){
		if(form.label.value == '' ){
		    alert('<?php echo JText::_('Field label could not be empty')?>');
			form.label.focus();
			return;
		}
		
		if(form.field_name.value == "" ){
		    alert('<?php echo JText::_('Field name could not be empty')?>');
			form.field_name.focus();
			return;
		}
		
		if (form.is_system.value==0)
		if(form.field_type.value == "" ){
		    alert('<?php echo JText::_('Field type could not be empty')?>');
			form.field_type.focus();
			return;
		}
		
		if(form.form_id.value == "" ){
		    alert('<?php echo JText::_('Please select form type')?>');
			form.form_id.focus();
			return;
		}
		
		if(form.table_name.value == "" ){
		    alert('<?php echo JText::_('Please select table type')?>');
			form.table_name.focus();
			return;
		}
		
		submitform( pressbutton );
	}					
	else {
		submitform( pressbutton );
	}
}
function select_direct_url(is_checked)
	{
		var form = document.adminForm;
		s_direct_url = document.getElementById('s_direct_url');
		if (is_checked)
		{
			
			s_direct_url.setStyle('display','');
		}
		else
		{
			s_direct_url.setStyle('display','none');
		}
		
	}
var field_validate_type = "";
window.addEvent('domready', function() {
    field_validate_type = document.getElementById('field_validate_type').value;
});	

function checkValidateType(value){
	if(value == "date" || value == "datetime"){
		if( !(document.getElementById('field_type').value == "DATE" || document.getElementById('field_type').value == "DATE_CAL") ){
			alert("Type of check: Date or DateTime format only apply for DATE or DATE CALENDAR field type");
			document.getElementById('field_validate_type').value = field_validate_type;
			return false;
		}
	}
	return true;
}
//-->
</script>
<?php $temp_id = $this->item->id;?>
<table class="admintable" style="width:100%;">	
	<tr>
		<td width="50%" valign="top">
			<fieldset>
			<legend><?php echo JText::_('Form preview')?></legend>
			<table class="admintable" style="width:100%;">	
            <?php
            $open = false;
            for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ ){
            	if ($this->fieldlist[$i]->field_name!='direct_url'){
	                $field = $this->fieldlist[$i];
	                $field_name = $field->field_name;
	                
	                if($field->field_type=='SEPERATOR'){?>
	                	<?php if($open){?>
		               </table>
						
					<?php }?>
						
							<h3 style="border-bottom: 1px dashed #DDDDDD; "><?php echo JText::_($field->label);?></h3>
							<table class="admintable">
	               	<?php }else{ ?>        
		                <tr class="row">
		                    <td class="key" width="20%" <?php if($field->id == $this->item->id){?> style="background:#FF5F5F"<?php }?>>
		                    	<a href="<?php echo JRoute::_( 'index.php?option='. $this->option .'&amp;view=jamanagefields&amp;task=edit&amp;cid[]='.$field->id ); ?>">
		                    		<?php echo JText::_($field->label); ?>
		                    	</a>
		                    </td>
		                    <td width="80%" <?php if($field->id == $this->item->id){?> style="background:#FF5F5F"<?php }?>>
		                        <?php
		                        echo rendfield($this->item, $field);
		                        ?>
		                    </td>
		                </tr>
	                <?php }

	                $open = true;
            	}
            }?>
		    </table>						
			</fieldset>
			
		</td>
		<td valign="top">
		<?php $this->item->id = $temp_id; ?>
		<?php 
			$this->item->label = str_replace('&','',$this->item->label);
			$this->item->label = str_replace('amp;#039;',"'",$this->item->label);
			
		?>
			<fieldset>
				<legend style="font-size:14px"><?php if($this->item->id) echo JText::_('Edit Field Item'); else echo JText::_('Form Field Item');?></legend>
				<form name="adminForm" action="index.php" method="post">
					<div style="width:100%;">
						<table class="admintable" border="0" style="width:100%">
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<?php echo JText::_( 'Field ID' ); ?>:
								</td>
								<td width="75%">
									<strong><?php echo $this->item->id; ?></strong>
								</td>
				        	</tr>	
				        	
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<font color="Red"><?php echo JText::_( 'Field Label' ); ?>:</font>
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="label" size="50" maxlength="255" value="<?php echo $this->item->label; ?>" /> 
									<font color="Red">*</font>
								</td>
								<tr>
								</td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right" >
									<font color="Red" class="editlinktip hasTip" title="<?php echo JText::_( 'FIELD NAME TOOLTIP' ); ?>"><?php echo JText::_( 'Field Name' ); ?>:</font>
								</td>
								<td width="75%">
									<input class="inputbox" type="text" <?php if($this->item->is_system){ ?> disabled="disabled"<?php }?>name="field_name" size="50" maxlength="255" value="<?php echo $this->item->field_name; ?>" />
									<br/>
									<small>(<?php  echo JText::_('An unique identifier for this field')?>)</small>
									<font color="Red">*</font>
								</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<font color="Red"><?php echo JText::_( 'Field Type' ); ?>:</font>
								</td>
								<td width="75%">
									<?php echo $this->lists['field_type']; ?>
									<?php if(in_array($this->item->field_type, array('MSELECT', 'SELECT', 'RADIO'))){?>
									<?php JHTML::_('behavior.modal', 'a.modal'); ?>
									<a class="modal" title="<?php echo JText::_('Click here to edit options');?>"  href="index.php?option=com_jajobboard&view=jacodes&tmpl=component&field_id=<?php echo $this->item->table_name.'_'.$this->item->field_name;  ?>" rel="{handler: 'iframe', size: {x: 650, y: 375}}"><?php echo JText::_('Edit Option');?></a>
									<?php }?>
									
									<?php if($this->item->id>0){ ?>
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'You need to make sure the change is right and necessary, because changing field type can lose data' ); ?>">
										<img border="0" alt="Tooltip" src="<?php global $mainframe; echo $mainframe->getSiteURL()?>/includes/js/ThemeOffice/warning.png"/>
									</span>	
									<?php }?>
									<font color="Red">*</font>
								</td>
				        	</tr>
<!--				        	<tr>
				        		<td class="key" width="25%" align="right">
				        			<?php echo JText::_('Image width'); ?>
				        		</td>
				        		<td width="75%">
				        			<input class="inputbox" type="text" name="image_width" <?php echo $this->item->field_type=='IMAGE'?'':'disabled'; ?> size="50" maxlength="255" value="<?php echo $this->item->image_width; ?>" />
				        		</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
				        			<?php echo JText::_('Image height'); ?>
				        		</td>
				        		<td width="75%">
				        			<input class="inputbox" type="text" name="image_height" <?php echo $this->item->field_type=='IMAGE'?'':'disabled' ?> size="50" maxlength="255" value="<?php echo $this->item->image_height; ?>" />
				        		</td>
				        	</tr>-->
				        	<tr>
				        		<td class="key" width="25%" align="right">
				        			<span class="editlinktip hasTip" title="<?php echo JText::_( 'Set default value for this field' ); ?>">
										<?php echo JText::_( 'Init Value' ); ?>:
									</span>		
									
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="field_init" size="50" maxlength="255" value="<?php echo $this->item->field_init; ?>" />									
								</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<font color="Red" class="editlinktip hasTip" title="<?php echo JText::_( 'FORM NAME TOOLTIP' ); ?>"><?php echo JText::_( 'Form name' ); ?>:</font>
								</td>
								<td width="75%">
									<?php echo $this->lists['form']; ?>
									<font color="Red">*</font>  
								</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<font color="Red"><?php echo JText::_( 'Table name' ); ?>:</font>
								</td>
								<td>
									<?php echo $this->lists['table_name']?>
									<?php if($this->item->id>0){ ?>
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'You need to make sure the change is right and necessary, because the change field type can lose data' ); ?>">
										<img border="0" alt="Tooltip" src="<?php global $mainframe; echo $mainframe->getSiteURL()?>/includes/js/ThemeOffice/warning.png"/>
									</span>	
									<?php }?>
									<font color="Red">*</font>
								</td>
							</tr>
							<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'PUBLISHED TOOLTIP' ); ?>">
									<?php echo JText::_( 'Published' ); ?>:
									</span>
								</td>
								<td width="75%">
									<?php if (!$this->item->is_system) echo JHTML::_('select.booleanlist', 'published', '', $this->item->published); else echo JHTML::_('select.booleanlist', 'published', 'disabled', $this->item->published); ?>  
								</td>
				        	</tr>
				        	<!--<tr>
				        		<td class="key" width="25%" align="right">
									<?php echo JText::_( 'Field Section' ); ?>:
								</td>
								<td width="75%">
									<?php echo $this->lists['section']; ?>  
								</td>
				        	</tr>-->
				        	<tr>
				        		<td colspan="2"><?php echo JText::_('Validation (only required fields are validated)')?></td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'IS REQUIRED TOOLTIP' ); ?>">
										<?php echo JText::_( 'Is Required' ); ?>?
									</span>
								</td>
								<td width="75%">
									<?php echo $this->lists['is_required']; ?>
								</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'TYPE OF CHECK TOOLTIP' ); ?>">
										<?php echo JText::_( 'Type of Check' ); ?>
									</span>
								</td>
								<td width="75%">
									<?php echo $this->lists['field_validate_type']; ?>  
								</td>
				        	</tr>
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'ERROR MESSAGE TOOLTIP' ); ?>">
										<?php echo JText::_( 'Error Message' ); ?>
									</span>
									
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="error_message" size="50" maxlength="255" value="<?php echo $this->item->error_message; ?>" />  
									<?php echo JText::_( 'The reason for the error. Ex: The field was not filled or Invalid value' ); ?>
								</td>
				        	</tr>
				        	<!-- Display Section -->
				        	<tr>
				        		<td colspan="2"><?php echo JText::_('Display');?></td>
				        	</tr>
				        	
				        	<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'FIELD ORDER TOOLTIP' ); ?>">
										<?php echo JText::_( 'Field Order' ); ?>:
									</span>
									
								</td>
								<td>
									<?php echo $this->lists['field_ordering']?>
								</td>
							</tr>
				        	<!--<tr>
				        		<td class="key" width="25%" align="right">
									<?php echo JText::_( 'Field Is On Search Form' ); ?>:
								</td>
								<td>
									<?php echo $this->lists['is_on_search']; ?>
									<?php echo str_repeat("&nbsp;", 4) . JText::_( 'Field Search Order' ); ?>:
									 &nbsp;
									<input class="inputbox" type="text" name="seach_ordering" size="5" maxlength="3" value="<?php echo $this->item->search_ordering; ?>" />   
									<?php  echo JText::_('Field Search Order Desc')?>
								</td>
								</td>
							</tr>-->
							<tr>
				        		<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'FIELD IS ON FILTER TOOLTIP' ); ?>">
										<?php echo JText::_( 'Field Is On Filter' ); ?>:
									</span>
								</td>
								<td>
									<?php echo $this->lists['is_on_filter']; ?>									
									
								</td>
								
							</tr>
							
				        	<!-- Parameters Section -->
				        	<tr>
				        		<td colspan="2"><?php echo JText::_('Parameters')?></td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'DISPLAY MODE TOOLTIP' ); ?>">
										<?php echo JText::_( 'Display mode' ); ?>:
									</span>
									
								</td>
								<td width="75%">
									<select name="display">
										<option value="" <?php if($this->item->display=='') echo "selected"; ?>>
											<?php echo JText::_( 'Select display mode' ); ?>
										</option>
										<option value="show_all" <?php if($this->item->display=='show_all') echo "selected"; ?>>
											<?php echo JText::_( 'Show all on Front-end' ); ?>
										</option>
										<option value="show_all_registered" <?php if($this->item->display=='show_all_registered') echo "selected"; ?>>
											<?php echo JText::_( 'Show all on Front-end for Registered users only' ); ?>
										</option>
										<!--<option value="not_edit" <?php if($this->item->display=='not_edit') echo "selected"; ?>>
											<?php echo JText::_( 'Show all and view only' ); ?>
										</option>-->
										<option value="hide_on_new" <?php if($this->item->display=='hide_on_new') echo "selected"; ?>>
											<?php echo JText::_( 'Hide on new form and view only on edit form' ); ?>
										</option>
										<option value="hide_on_view" <?php if($this->item->display=='hide_on_view') echo "selected"; ?>>
											<?php echo JText::_( 'Show on New | Edit form and hide on view' ); ?>
										</option>
										<option value="hide_on_edit" <?php if($this->item->display=='hide_on_edit') echo "selected"; ?>>
											<?php echo JText::_( 'Show on New and view only on edit form' ); ?></option>
										<option value="hide_all" <?php if($this->item->display=='hide_all') echo "selected"; ?>>
										<?php echo JText::_( 'Hide all on Front-end' ); ?></option>
										<option value="admin_only" <?php if($this->item->display=='admin_only') echo "selected"; ?>>
										<?php echo JText::_( 'Admin Only' ); ?></option>
										
									</select>
									<font color="Red">*</font>
								</td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'WIDTH TOOLTIP' ); ?>">
										<?php echo JText::_( 'Width' ); ?>:
									</span>
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="field_width" size="10" maxlength="10" value="<?php echo $this->item->field_width; ?>" />   
								</td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'Height TOOLTIP' ); ?>">
										<?php echo JText::_( 'Height' ); ?>:
									</span>
									
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="field_height" size="10" maxlength="10" value="<?php echo $this->item->field_height; ?>" />   
									<?php echo JText::_('For textarea or multipe selection field')?> 
								</td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'Class name TOOLTIP' ); ?>">
										<?php echo JText::_( 'Class name' ); ?>:
									</span>
								</td>
								<td width="75%">
									<input class="inputbox" type="text" name="field_class" size="60" maxlength="10" value="<?php echo $this->item->field_class; ?>" />   
								</td>
				        	</tr>
				        	
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <?php echo JText::_( 'Readonly/Disabled' ); ?>:
				                </td>
				                <td width="75%">
				                    <?php echo $this->lists['is_readonly'] ?> (<?php echo JText::_('Readonly or can be editted on Front-end');?>)
				                </td>
				            </tr>
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <?php echo JText::_( 'Mouse Event' ); ?>:
				                </td>
				                <td width="75%">
				                    <?php echo $this->lists['mouseevents']?>
				                </td>
				            </tr>
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <?php echo JText::_( 'Function Javascript' ); ?>:
				                </td>
				                <td width="75%">
				                    <input type="text" value="<?php echo $this->item->functionjs; ?>" name="functionjs" id="functionjs" size="60"/>
				                </td>
				            </tr>
				            <tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'FIELD EXAMPLE TOOLTIP' ); ?>">
										<?php echo JText::_( 'Field Example' ); ?>:
									</span>
									
								</td>
								<td width="75%">									
									<input class="inputbox" type="text" name="field_example" size="60" maxlength="100" value="<?php echo $this->item->field_example; ?>" />   
									<br />
									<?php echo JText::_('Field Example Desc')?>
								</td>
				        	</tr>
				        	<tr>
								<td class="key" width="25%" align="right">
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'FIELD Comment TOOLTIP' ); ?>">
										<?php echo JText::_( 'Field Comment' ); ?>:
									</span>
								</td>
								<td width="75%">
									<textarea name="field_comment" cols="40" rows="5"><?php echo $this->item->field_comment; ?></textarea>									 
									<br />
									<?php echo JText::_('(Comment to be displayed next field. Like this one you are reading now)')?>
								</td>
				        	</tr>
				        	
				        	<!-- Database Section -->
				        	<tr>
				        		<td colspan="2"><?php echo JText::_('Reference Database')?></td>
				        	</tr>
				        	
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <font><?php echo JText::_( 'Is Referred' ); ?>:</font>
				                </td>
				                <td>
				                    <?php echo $this->lists['is_referred']; ?>
				                </td>
				            </tr>
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <font><?php echo JText::_( 'Referred Key' ); ?>:</font>
				                </td>
				                <td>
				                    <input class="inputbox" type="text" name="referred_key" size="20" maxlength="20" value="<?php echo $this->item->referred_key; ?>" />   
				                </td>
				            </tr>
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <font><?php echo JText::_( 'Referred Value' ); ?>:</font>
				                </td>
				                <td>
				                    <input class="inputbox" type="text" name="referred_value" size="20" maxlength="20" value="<?php echo $this->item->referred_value; ?>" />   
				                </td>
				            </tr>
				            <tr>
				                <td class="key" width="25%" align="right">
				                    <font><?php echo JText::_( 'Referred Table' ); ?>:</font>
				                </td>
				                <td>
				                    <input class="inputbox" type="text" name="referred_table" size="20" maxlength="20" value="<?php echo $this->item->referred_table; ?>" />   
				                </td>
				            </tr>
						</table>
					</div>
					<input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
				<input type="hidden" name="cid[]" value="<?php echo $this->item->id; ?>" />
				<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
				<input type="hidden" name="view" value="jamanagefields" />
				<input type="hidden" name="boxchecked" value="1" />
				<input type="hidden" name="is_system" value="<?php echo ($this->item->is_system!=null)?$this->item->is_system:0; ?>" />
				<input type="hidden" name="task" value="" />
				<?php echo JHTML::_( 'form.token' ); ?>	
			 </form>
				</fieldset>
				
			 

		</td>
	</tr>
</table>